From 7a521ca53f8e16e5734441ecdf4d186cd6c8c1b5 Mon Sep 17 00:00:00 2001
From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?=
If babls conversion isn't fast enough, you can provide @@ -201,48 +203,51 @@
The simplest scenario for using babl is converting between linear - buffers represented by an existing BablPixelFormat. +
babl_process (babl_fish (source_format, destination_format), + source_buffer, destination_buffer, + pixel_count);+ +
The processing operation that babl performs is copying including + conversions if needed between linear buffers containing the same count + of pixels, with different pixel formats.
+const Babl *srgb = babl_format ("R'G'B' u8"); const Babl *lab = babl_format ("CIE Lab float"); const Babl *rgb_to_lab_fish = babl_fish ( srgb, lab); -int width = 123, height = 581, pixel_count = width * height; + float *lab_buffer; unsigned char *srgb_buffer; srgb_buffer = malloc (pixel_count * srgb->format.bytes_per_pixel); - -/* load data into srgb_buffer */ - lab_buffer = malloc (pixel_count * 3 * 4); +...... load data into srgb_buffer ....... + babl_process (bablfish, srgb_buffer, lab_buffer, pixel_count); -/* do operation in lab space */ -babl_process (babl_fish(lab, srgb), - lab_buffer, srgb_buffer, pixel_count);+...... do operation in lab space ........ -/* the data has now been transformed back to srgb data */ +babl_process (babl_fish(lab, srgb), + lab_buffer, srgb_buffer, pixel_count); - +/* the data has now been transformed back to srgb data */
If the existing pixel formats are not sufficient for your conversion needs, new ones can be created on the fly. The constructor will provide the prior created one if duplicates are registered.
format = babl_format_new (babl_model ("R'G'B'"), - babl_type ("u8"), - babl_component ("B'"), - babl_component ("G'"), - babl_component ("R'"), - NULL);+>const Babl *format = babl_format_new (babl_model ("R'G'B'"), + babl_type ("u16"), + babl_component ("B'"), + babl_component ("G'"), + babl_component ("R'"), + NULL); -
babl_process (babl_fish (source_format, destination_format), - source_buffer, destination_buffer, - pixel_count);+
Through the environment variable BABL_ERROR you can control + a speed/performance trade off that by default is set very low (0.000001) + values in the range 0.01-0.1 can provide reasonable preview performance + by allowing lower numerical accuracy
.